/**
 *  Version:     @(#)aio_util.c    1.2.14 18/07/2007
 *
 *  Authors:     Hailong Xia <hlxxxx@gmail.com> 
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty 
 *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
 *  the GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General
 *  Public License along with this library; if not, write to the 
 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 *  Boston, MA 02111-1307  USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#ifdef _WIN32
# include <winsock2.h>
# include <sys/timeb.h>
#endif

#include "aio_util.h"

#ifdef _WIN32
int
gettimeofday(struct timeval *tv, struct timezone *tz)
{
        struct _timeb tb;

        if(tv == NULL)
                return -1;

        _ftime(&tb);
        tv->tv_sec = (long)tb.time;
        tv->tv_usec = ((int)tb.millitm) * 1000;
        return 0;
}
#endif

#ifdef _AIO_DEBUG
void 
view_buffer(const char *buffer, int size)
{
        int i, j = 0;

    	fprintf(stderr, "\n----------------------------\n");
    	for(i = 0; i < size; i++, j++){
		if(j % 4 == 0)
			fprintf(stderr, " %c ", '|');
        	if(isprint(buffer[i]))
            		fprintf(stderr, "%c ", buffer[i]);
        	else
            		fprintf(stderr, "[0x%02X]", buffer[i]);
    	}

    	if(i % 10 == 0)
        	fprintf(stderr, "\n");
    	fprintf(stderr, "\n----------------------------\n");
}
#endif

